<template>
  <vab-app />
</template>

<script lang="ts" setup>
import { noDebugger } from '/@/config/index'
import { useSettingsStore } from '/@/store/modules/settings'
defineOptions({
  name: 'App',
})
const route = useRoute()

const settingsStore = useSettingsStore()
const { updateTheme, changeColor } = settingsStore

const { device, theme } = storeToRefs(settingsStore)
const resizeContainer = () => {
  let vh = window.innerHeight * 0.01
  const el = ref<HTMLElement | null>(null)
  useCssVar('--vh', el).value = `${vh}px`
}
// watch(
//   route,
//   () => {
//     console.log(route.path, 'a')

//     if (device.value === 'mobile') {
//       theme.value.layout = 'vertical'
//     } else {
//       if (route.path === '/meeting/manage') theme.value.layout = 'horizontal'
//       else {
//         if (localStorage.getItem('shop-vite-theme'))
//           theme.value.layout = JSON.parse(localStorage.getItem('shop-vite-theme') as string).layout || layout
//         else theme.value.layout = layout
//       }
//     }
//   },
//   { immediate: true }
// )
onBeforeMount(() => {
  changeColor()
  updateTheme()

  /**
   * @description: 修复ios、android等移动端浏览器100vh兼容问题
   * @author sundan
   */

  window.addEventListener('orientationchange', resizeContainer)
  window.addEventListener('resize', resizeContainer)
  resizeContainer()

  // 是否允许生产环境进行代码调试，请前往config/cli.config.ts文件配置
  ;(() => {
    if (
      !location.hostname.includes('127') &&
      !location.hostname.includes('localhost') &&
      (location.hostname.includes('beautiful') || location.hostname.includes('vuejs-core') || noDebugger)
    ) {
      const block = () => {
        setInterval(() => {
          let startTime = performance.now()
          if (window.outerHeight - window.innerHeight > 200 || window.outerWidth - window.innerWidth > 200) {
            let message = '本地址禁止调试！'
            if (location.hostname.includes('beautiful') || location.hostname.includes('vuejs-core')) message = '本地址禁止调试！'
            document.body.innerHTML = `<h1>${message}</h1>`
          }
          ;(function () {
            return false
          })
            ['constructor']('debugger')
            ['call']()
          let endTime = performance.now()
          if (endTime - startTime > 1000) window.location.href = 'about:blank'
        }, 1000)
      }
      try {
        block()
      } catch {
        /* empty */
      }
    }
  })()
})
</script>
